<!DOCTYPE html>
<html>

<head>
    <title>我收到的点赞</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.css">
    <script src="/js/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/message.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>

    <script>
        $(function () {
            var userId = getParams().id;
            var currentPage = 1;
            var pages;
            var praises;

            /*查询收到的所有点赞,已读,未读,时间倒序,未读有个标记*/
            $.get("/users/" + userId + "/praises", function (data) {
                praises = data.list;
                pages = data.pages;
                /*把类型和对应的id封装成一个数组*/
                $.map(praises, function (ele, index) {
                    ele.arrs = [ele.typeName, ele.typeId]
                    return ele;
                });
                renderViews($(".praises"), praises);

            });

            /*动态绑定点击事件,标记已读*/
            $(".setRead").on("click", "a[data-pid]", function () {
                var pid = $(this).data('pid');
                $.post("/praise", {id: pid}, function (data) {
                    location.reload();
                });
            })

            /*翻页*/
            $(window).scroll(function () {
                if (isEnd()) {
                    if (currentPage < pages) {
                        currentPage++;
                        $.get("/users/" + userId + "/praises", {currentPage: currentPage}, function (data) {
                            praises = $.merge(praises, data.list);
                            console.log(praises);
                            /*把类型和对应的id封装成一个数组*/
                            $.map(praises, function (ele, index) {
                                ele.arrs = [ele.typeName, ele.typeId]
                                return ele;
                            });
                            renderViews($(".praises"), praises);
                        });
                    } else {
                        $(document).dialog({
                            type: "notice",
                            infoText: "没有更多了",
                            autoClose: 1500,
                            position: "center"
                        });
                    }
                }
            });

            /*渲染界面*/
            function renderViews(ele, value) {
                ele.renderValues({list: value}, {
                    handle: function (ele, value) {
                        console.log(ele);
                        console.log(value);
                        if (value[0] == "游记") {
                            ele.href = "/travelComment.html?id=" + value[1];
                        } else if (value[0] == "评论") {
                            ele.href = "/strategyComment.html?id=" + value[1];
                        }
                    },
                    readHandle: function (ele, value) {
                        if (value == 0) {
                            $(ele).css("display", "");
                        }
                    },
                    userHandle: function (ele, value) {
                        ele.href = "/userProfiles.html?id=" + value;
                    }
                })
            }

        })


    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我收到的点赞</span>
        </div>
        <div class="col"></div>
    </div>
</div>


<div class="container praises setRead">
    <ul class="list-group" render-loop="list">

        <li class="list-group-item d-flex justify-content-between align-items-center ">
            <div class="item">
                <p>
                    <a render-key="list.doer.id" render-fun="userHandle">
                        <img class="rounded-circle" width=40px
                             height="40px"
                             render-src="list.doer.headImgUrl">
                        <span render-html="list.doer.nickName" style="color: #ff8a00"></span>
                    </a>
                    <span><i class="fa fa-thumbs-up" style="color: #BBBBBB"></i></span>
                    <span>赞了我的</span>
                    <span render-html="list.typeName" style="color: #ff8a00"></span>
                    <span class="badge badge-pill badge-danger readMark"
                          render-key="list.reader" render-fun="readHandle" style="display: none"
                    >未读</span>
                </p>
                <a render-attr="data-pid=list.id">
                    <div align="center">
                        <p>

                            <span render-html="list.travelOrComment.title"></span>

                        </p>
                        <p render-html="list.praiseDate"></p>
                    </div>
                </a>
            </div>
            <div class="setRead">
                <a render-key="list.arrs" render-fun="handle" render-attr="data-pid=list.id">
                    <i class="fa fa-chevron-right "></i>
                </a>
            </div>
        </li>
    </ul>
</div>
</body>

</html>